<%@ page language="java" import="java.lang.*" import="java.sql.*" %>

<%
            Connection con = null;
            String str = request.getParameter("r1");
            String name = request.getParameter("empname");
            String code = request.getParameter("empid");
            int EmpID = Integer.parseInt(code);
            try {
                Class.forName("com.microsoft.sqlserver.jdbc.SQLServerDriver");
                con = DriverManager.getConnection("jdbc:sqlserver://localhost:1433;databaseName=JspJavaScript", "sa", "fat123456");
                String sql = "delete from Employee where empid= ?";
                PreparedStatement stmt = null;
                stmt = con.prepareStatement(sql);
                stmt.setInt(1, EmpID);
                int erase = stmt.executeUpdate();
                if (erase == 0) {%>
                <script language="javascript">
                    alert("Deletion successful");
                </script>
                <%    }
                if (erase == 1) {%>
                <script language="javascript">
                    alert("Deletion successful");
                </script>
                <%                }

                stmt.close();
                con.close();
                out.println("Data delete successfully from database.");
            } catch (Exception e) {
                out.println(e);
            }
%>